<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ include file="checkLogin.inc.jsp" %>

<%@ page import="java.util.List" %>
<%@ page import="java.util.LinkedList" %>
<%@ page import="kulstats.*" %>

<%

ActivityManager activityManager = Registry.activityManager();
Activity curAct = activityManager.getLastActivity(currentUser);
System.out.println(curAct);
long curAct_time = 0;
long curAct_pause = 0;
long curAct_paused = 0;
long curAct_prog1 = 0;
long curAct_prog2 = 0;
String curAct_type = "";
if(curAct != null && curAct.getStopDate() == null) {
	curAct_time = curAct.getStartDate().getTime();
	System.out.println("doen!:"+curAct_time);
	curAct_pause = (curAct.getAType()==ActivityType.STUDY ? (((Study)curAct).getLastPauseDate()!=null ? 
			((Study)curAct).getLastPauseDate().getTime() : 0) : 0);
	curAct_paused = (curAct.getAType()==ActivityType.STUDY ? ((Study)curAct).getPaused() : 0);
	curAct_type = curAct.getAType().toString().toLowerCase() ;
	if(curAct.getStopDate() != null) {
		curAct = null;
	}
	
	if(curAct instanceof getCourseable) {
		MilestoneController msCon = MilestoneController.getInstance();
		Course curCourse = ((getCourseable)curAct).getCourse(); 
		LinkedList<Long> progs = msCon.getProgressWhileTracking(curCourse.getCourseID());
		curAct_prog1 = progs.get(0);
		curAct_prog2 = progs.get(1);
	}
}
else {
	curAct = null;
}


%>
<!DOCTYPE html>
<html> 
<head> 
	<title>Tracker - StAPP</title> 
	
	<%@ include file="mobileResources.inc.jsp" %>
	
</head>

<body>

<div data-role="page" id="trackPage">
	<div data-role="header">
		<% WebCache.headerElement = "track"; %>
		<%@ include file="mobileHeader.inc.jsp" %>
	</div><!-- /header -->
	<div data-role="content" id="content_init" <%=(curAct!=null ? "style=\"display:none;\"" : "") %>>
		<h3>Start tracking</h3>
		<!-- <div style="display: none;">
		<ul data-role="controlgroup" data-type="horizontal" class="ui-corner-all ui-controlgroup ui-controlgroup-horizontal" id="butt_track_group">
			<li><a class="ui-block-a" data-role="button" id="butt_track_study" name="butt_track_study" data-theme="b">Study</a></li>
			<li><a class="ui-block-b" data-role="button" id="butt_track_class" name="butt_track_class" data-theme="a">Class</a></li>
			<li><a class="ui-block-c" data-role="button" id="butt_track_other" name="butt_track_other" data-theme="a">Other</a></li>
		</ul>
		</div> -->
		
		<form action="DoTrack" method="post" id="track_form" data-ajax="false">
			<input type="hidden" name="track_type" id="track_type" value="<%=curAct_type %>" />
			<input type="hidden" name="track_start" id="track_start" value="<%=curAct_time %>" />
			<input type="hidden" name="track_time"  id="track_time" value="" />
			<input type="hidden" name="track_paused" id="track_paused" value="<%=curAct_paused %>" />
			<input type="hidden" name="track_prog1" id="track_prog1" value="<%=curAct_prog1 %>" />
			<input type="hidden" name="track_prog2" id="track_prog2" value="<%=curAct_prog2 %>" />
			<input type="hidden" name="track_pause_start" id="track_pause_start" value="<%=curAct_pause %>" />
			
			<div data-role="fieldcontain" id="div_trackselect">
	    		<fieldset data-role="controlgroup" id="div_trackselect2">
	         			<input type="radio" name="track_type_select" class="ui-block-a track_type_select" id="track_type_study" value="study" checked="checked" />
	        		 	<label for="track_type_study">Study</label>
	        		 	<input type="radio" name="track_type_select" class="ui-block-b track_type_select" id="track_type_class" value="lesson"  />
	        		 	<label for="track_type_class">Class</label>
	        		 	<input type="radio" name="track_type_select" class="ui-block-c track_type_select" id="track_type_other" value="spare_time"  />
	        		 	<label for="track_type_other">Spare Time</label>
	   			</fieldset>
	    	</div>
			
			<div id="div_track_lesson_type" data-role="fieldcontain" style="display: none;">
	    		<fieldset data-role="controlgroup" data-type="horizontal">
	         			<input type="radio" name="track_lesson_type" id="track_lesson_type_1" value="lecture" checked="checked" />
	        		 	<label for="track_lesson_type_1">Lecture</label>
	        		 	<input type="radio" name="track_lesson_type" id="track_lesson_type_2" value="practice"  />
	        		 	<label for="track_lesson_type_2">Practice</label>
	   			</fieldset>
	    	</div>
	    	
		<!-- different form objects for different types of activities -->
			<div id="div_track_course" data-role="fieldcontain">
				<label for="track_course" class="select">Course:</label>
				<select name="track_course" id="track_course">
					<!-- <option value="test-course">Test course</option> -->
<%
List<Course> userCourses = currentUser.getCourses();
//System.out.println(currentUser);
//System.out.println(userCourses);
for(Course c : userCourses) {
	if(c != null) {
%>
					<option value="<%=c.getCourseID() %>"><%=c.getName() %></option>
<%
	}
}
%>
				</select>
			</div>
<% /*
			<div id="div_track_location" data-role="fieldcontain" style="display: none;">
				<label for="track_location" class="select">Location:</label>
				<select name="track_location" id="track_location">
					<option value="test-location">Test location</option>
				</select>
			</div>
*/ %>
			<div id="div_track_spare_type" data-role="fieldcontain" style="display: none;">
				<label for="track_spare_type" class="select">Type:</label>
				<select name="track_spare_type" id="track_spare_type">
					<option value="eat"  >Eating</option>
					<option value="sleep">Sleeping</option>
					<option value="sport">Sports</option>
					<option value="hobby">Hobby</option>
					<option value="party">Party</option>
<%
/*for(SpareTimeType t : SpareTimeType.values()) {
%>
					<option value="<%=t.toString() %>"><%=t.readableString() %></option>
<%
}*/
%>
				</select>
			</div>
			
			<div data-role="button" id="butt_track_start">Start Tracking</div>
		</form>
	</div><!-- /content -->
	
	
	<div data-role="content" id="content_busy" <%=(curAct!=null ? "" : "style=\"display:none;\"") %>>
		<h3>Tracking activity...</h3>
		<div class="ui-grid-a" id="div_counters">
			<div class="ui-block-a"><strong>Total time:</strong></div>
			<div class="ui-block-b" style="display: none;" id="track_pauser_title">Pausing:</div>
			<div class="ui-block-a"><h2 id="track_counter">00:00:00</h2></div>
			<div class="ui-block-b" style="display: none;" id="track_pauser_count"><h4 id="track_pauser">00:00:00</h4></div>
		</div><!-- /grid-a -->
		<div id="track_pauser_slider" style="display: none;">
			<div data-role="button" id="button_pause_on">Pause</div>
			<div data-role="button" id="button_pause_off" style="display: none;">Continue studying</div>
			<!--  <select name="pause_flip" id="pause_flip" data-role="slider">
				<option value="study">Studying</option>
				<option value="pause">Pausing...</option>
			</select> -->
		</div>
		<div data-role="button" id="butt_track_stop">I'm Finished</div>
		<div id="track_milestoneprogress" style="display: none;">
		</div>
	</div><!-- /content -->
	
	
	<div data-role="content" id="content_questions" style="display: none;">
		<h3>Review your activity</h3>
		<form action="DoTrack" method="post" id="questionForm">
			<div data-role="fieldcontain" id="content_questions_questions"></div>
			
			<div id="content_questions_buttons" class="ui-grid-a">
				<div class="ui-block-a"><div data-role="button" id="button_questions_skip"  >Skip</div></div>
				<div class="ui-block-b"><div data-role="button" id="button_questions_submit" data-theme="b">Submit answers!</div></div>
			</div>
		</form>
	</div>
	
	
	<div data-role="content" id="content_finished" style="display: none;">
		<h3>Finished...</h3>
		<p id="content_finished_main">&nbsp;</p>
	</div>
	
	
	<div data-role="footer">
		<h4>&copy; 2011 - StAPP</h4>
	</div><!-- /footer -->
</div><!-- /page -->


</body>
</html>